package net.niufei.study.cpatterns.readwritelock;

public class Data {
	private String content = "a";
	private ReadWriteLock rwlock = new ReadWriteLock();
	
	public String read() {
		try {
			rwlock.readLock();
			return content;
		} catch (InterruptedException e) {
			return null;
		}
		finally {
			rwlock.readUnlock();
		}
	}
	
	public void write(String content) {
		try {
			rwlock.writeLock();
			this.content = content;
		} catch (InterruptedException e) {}
		finally {
			rwlock.writeUnlock();
		}
	}
}
